package com.ambow.service.master.sysinteractivelog.rest;

import com.ambow.apimodel.common.ResponseResult;
import com.ambow.apimodel.common.Status;
import com.ambow.service.master.sysinteractivelog.dto.SysInteractiveLogDTO;
import com.ambow.service.master.sysinteractivelog.service.SysInteractiveLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "/sysInteractiveLog-api")
@Slf4j
@Api(tags = {"SysInteractiveLogRest"})
public class SysInteractiveLogRest {
    @Autowired
    private SysInteractiveLogService sysInteractiveLogService;

    /**
     * 添加
     * @return
     */
    @RequestMapping(value = "/insertSysInteractiveLog", method = RequestMethod.POST)
    @ApiOperation(value = "添加", notes = "返回结果,SUCCESS:200,FAILED:500", httpMethod = "POST")
    public ResponseResult<SysInteractiveLogDTO> insertSysInteractiveLog(@RequestBody SysInteractiveLogDTO sysInteractiveLogDTO) throws Exception {
        ResponseResult<SysInteractiveLogDTO> result = new ResponseResult<>();
        try {
            int count = sysInteractiveLogService.insertSysInteractiveLog(sysInteractiveLogDTO);
            result.setStatus(Status.SUCCESS);
            result.setCount(count);
            result.setMessage("修改成功");
            return result;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            result.setStatus(Status.FAILED);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }

    /**
     * 获取SysInteractiveLog列表
     * @return
     */
    @RequestMapping(value = "/searchSysInteractiveLog", method = RequestMethod.POST)
    @ApiOperation(value = "获取SysInteractiveLog列表", notes = "返回结果,SUCCESS:200,FAILED:500", httpMethod = "POST")
    public ResponseResult<List<SysInteractiveLogDTO>> searchSysInteractiveLog(@RequestBody SysInteractiveLogDTO sysInteractiveLogDTO) throws Exception {
        ResponseResult<List<SysInteractiveLogDTO>> result = new ResponseResult<>();
        try {
            List<SysInteractiveLogDTO> entity = sysInteractiveLogService.searchSysInteractiveLog(sysInteractiveLogDTO);
            result.setStatus(Status.SUCCESS);
            result.setData(entity);
            result.setMessage("查询成功");
            return result;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            result.setStatus(Status.FAILED);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }

}